package com.hwz.hwzliving.commodity.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hwz.common.utils.PageUtils;
import com.hwz.common.utils.Query;

import com.hwz.hwzliving.commodity.dao.AttrgroupDao;
import com.hwz.hwzliving.commodity.entity.AttrgroupEntity;
import com.hwz.hwzliving.commodity.service.AttrgroupService;


@Service("attrgroupService")
public class AttrgroupServiceImpl extends ServiceImpl<AttrgroupDao, AttrgroupEntity> implements AttrgroupService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<AttrgroupEntity> page = this.page(
                new Query<AttrgroupEntity>().getPage(params),
                new QueryWrapper<AttrgroupEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params, Long categoryId) {
        //携带搜索框查询条件
        String key = (String) params.get("key");
        QueryWrapper<AttrgroupEntity> queryWrapper = new QueryWrapper<>();
        //如果搜索条件不为空就携带
        if (StringUtils.isNotBlank(key)){
            queryWrapper.eq("id", key).or().like("name", key);
        }
        //判断是否待遇categoryId
        if (categoryId != 0){
            queryWrapper.eq("category_id", categoryId);
        }

        IPage<AttrgroupEntity> page = this.page(
                new Query<AttrgroupEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

}